home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12470 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.7 KB  |  101 lines

  1. Path: news.luc.edu!user
  2. From: VArase@varase.it.luc.edu (Verne Arase)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Borland C's tmpnam()
  5. Date: Sun, 31 Mar 1996 21:18:35 -0600
  6. Organization: LUMC
  7. Message-ID: <AD84A72B9668171739@mcdiala03.it.luc.edu>
  8. References: <AD75E5DC9668E2A52@mcdiala13.it.luc.edu> <Pine.A32.3.91.960322134158.23347A-100000@red.weeg.uiowa.edu> <AD78E5E796681EC58@mcdialb10.it.luc.edu> <827626790snz@genesis.demon.co.uk>  <Pine.SOL.3.90.960324183336.6304B-100000@eddie> <828277392snz@genesis.demon.co.uk>
  9. NNTP-Posting-Host: 147.126.240.103
  10.  
  11. In article <828277392snz@genesis.demon.co.uk>,
  12. Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
  13.  
  14.  >>This leads me to believe that the file names produced by tmpnam could
  15. exist
  16.  >>but they are of a specific pattern which you can avoid. For example, gcc
  17. on
  18.  >>OS/2 produces the filenames 10000000.tmp, 10000001.tmp, etc. So you
  19. should
  20.  >>avoid using filenames ending in .tmp in OS/2.
  21.  >
  22.  >That might be reasonable for implementation to do but there is no
  23.  >such guarantee in the standard.
  24.  
  25. The file names returned by Borland C's tmpnam() are in the form
  26. "tmp%u.$$$", and do insure that the file name is unique in the current
  27. directory.
  28.  
  29. This is the version I'm using now which allows specification of a target
  30. directory:
  31.  
  32. -------
  33.  
  34. /*
  35.    Function name: tempname.c
  36.  
  37.    Function:      Return unique file name for target directory
  38.  
  39.    Language:      This program was compiled using Borland C Version 4.5.2
  40.  
  41. */
  42.  
  43. #include <stdio.h>
  44. #include <dir.h>
  45. #include <ctype.h>
  46. #include "IPUtil.h"
  47.  
  48.  
  49. Boolean           /* return a temporary file name */
  50.                   tempname(
  51.  
  52.    /* parameters */
  53.    Byte           *where,        /* drive:directory */
  54.    Byte           *filename)     /* returned file name */ {
  55.  
  56.    /* local variables */
  57.    Byte           svl[MAXDRIVE], /* specification volume */
  58.                   sdr[MAXDIR],   /* specification directory */
  59.                   sfl[MAXFILE],  /* specification file name */
  60.                   sex[MAXEXT],   /* specification extension */
  61.                   tvl[MAXDRIVE], /* tmpnam volume */
  62.                   tdr[MAXDIR],   /* tmpnam directory */
  63.                   tfl[MAXFILE],  /* tmpnam file name */
  64.                   tex[MAXEXT],   /* tmpnam extension */
  65.                   odir[MAXDIR];  /* old directory */
  66.    int            odsk,          /* old disk */
  67.                   what;          /* attributes */
  68.    Boolean        err=False;     /* error */
  69.  
  70.    /* begin of code */
  71.    odsk=getdisk();               /* get current disk */
  72.    what=fnsplit(where,           /* get specified directory */
  73.       svl,sdr,sfl,sex);
  74.    if (what&DRIVE)               /* if user specified drive ... */
  75.       setdisk(toupper(svl[0])-'A'); /* set disk */
  76.    if (!getcurdir(0,odir)) {     /* if no error getting the cur dir ... */
  77.       if (what&DIRECTORY) {         /* if user specified directory ... */
  78.          if (!chdir(sdr)) {            /* if directory reset ... */
  79.             tmpnam(filename);             /* set file name */
  80.             if (chdir(odir))              /* if error resetting dir ... */
  81.                err=True;                     /* set error */
  82.             }
  83.          else err=True;                /* else error */
  84.          }
  85.       else tmpnam(filename);        /* else use current directory */
  86.       }
  87.    else err=True;                /* else error */
  88.    setdisk(odsk);                /* reset default disk */
  89.    if (!err) {                   /* if no error ... */
  90.       what=fnsplit(filename,        /* split tmpnam */
  91.          tvl,tdr,tfl,tex);
  92.       fnmerge(filename,             /* merge temporary name */
  93.          svl,sdr,tfl,tex);
  94.       }
  95.    return err;                   /* return error status */
  96.    }  /* tempname */
  97.  
  98.  
  99. ---
  100. The above are my own opinions, and not those of my employer.
  101.